package com.xyxeshang.es.music.backend.exception;


import com.xyxeshang.es.music.backend.constant.ResultConstant;

/**
 * @author xyx-Eshang
 */
public class CustomException extends Exception {
	/**
	 * 状态码
	 */
	private Integer code;
	/**
	 * 异常信息
	 */
	private String message;

	public CustomException() {
		super();
	}

	public CustomException(Exception e) {
		this.code = ResultConstant.ERROR;
		this.message = ResultConstant.messageMap.get(code) + "\n异常信息如下：\n" + e.getMessage();
	}

	public CustomException(Integer code) {
		this.code = code;
		this.message = ResultConstant.messageMap.get(code);
	}

	public CustomException(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public CustomException(String methodSignature, String parameterName) {
		this.code = 40001;
		this.message = "执行方法 " + methodSignature + " 时，传入的参数 " + parameterName + " 为空";
	}

	@Override
	public String toString() {
		return "CustomException{" +
				"code=" + code +
				", message='" + message + '\'' +
				'}';
	}

	public Integer getCode() {
		return code;
	}

	public CustomException setCode(Integer code) {
		this.code = code;
		return this;
	}

	@Override
	public String getMessage() {
		return message;
	}

	public CustomException setMessage(String message) {
		this.message = message;
		return this;
	}
}
